package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.TimeUtils;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;
import com.kmproject.haifu.mvp.ui.holder.SmartViewHolder;

import java.util.List;

public class SecondHandImportToStoreAdapter extends BaseQuickAdapter<SecondHandInfoBean, BaseViewHolder> {
    ImageLoader glideImage;
    private boolean isShowCheck = false;//选择开关
    private int isselectAll = 0;//0表示既不是选择全部，也不是全部不选，1表示全选中  2表示全不选
    public SecondHandImportToStoreAdapter( @Nullable List<SecondHandInfoBean> data) {
        super(R.layout.secondhand_obt_item, data);
    }



    @Override
    protected void convert(BaseViewHolder helper, SecondHandInfoBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setVisibility(View.VISIBLE);
        helper.<TextView>getView(R.id.secondhand_obt_item_title).setText(item.getLowerShelfReasonName());
        if (item.getImages()!=null&&!item.getImages().isEmpty())
        {
            glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getImages().get(0).getImageUrl())
                    .imageView(helper.<ImageView>getView(R.id.houserenting_main_content_item_img))
                    .build());
        }

            helper.<LinearLayout>getView(R.id.secondhand_obt_item_del).setVisibility(View.INVISIBLE);

        helper.addOnClickListener(R.id.secondhand_obt_item_del);
        helper.<TextView>getView(R.id.secondhand_obt_item_name).setText(item.getTitle());

        helper.<TextView>getView(R.id.secondhand_obt_item_content).setText(item.getViewCount()+"次浏览，"+item.getCollectionCount()+"人想要");
        helper.<TextView>getView(R.id.secondhand_obt_item_price).setText(item.getSalePrice()+"P");


        if (isShowCheck) {
            if (isselectAll == 1) {
                helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setChecked(true);
                item.setHaveSelect(true);
            } else if (isselectAll == 2) {
                helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setChecked(false);
                item.setHaveSelect(false);
            }else {
                helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setChecked(item.isHaveSelect());
            }
            helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setVisibility(View.VISIBLE);
            helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    item.setHaveSelect(isChecked);

                }
            });
        } else {
            helper.<CheckBox>getView(R.id.houseRentingShow_item_selectImg).setVisibility(View.GONE);
            item.setHaveSelect(false);
        }
    }

    /**
     *是否选中全部
     * @param isselectAll
     */
    public void setIsselectAll(int isselectAll) {
        this.isselectAll = isselectAll;
        notifyDataSetChanged();
    }



    /**
     * 控制是否显示删除
     * @param showCheck
     */
    public void setShowCheck(boolean showCheck) {
        isShowCheck = showCheck;
        notifyDataSetChanged();
    }
}
